package com.slkj.shilixiaoyuanapp.ui.parent.tool.bodyartspecialty;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;
import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.entity.parent.SingleBodyartspecialtyEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.common.ChosePeopleActivity;
import com.slkj.shilixiaoyuanapp.ui.common.adapter.ChosePicAdapter;
import com.slkj.shilixiaoyuanapp.ui.parent.tool.leave.LeaveDspActivity;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import butterknife.BindView;
import butterknife.OnClick;

import static com.slkj.shilixiaoyuanapp.entity.code.UiCode.CHOSE_PIC_SPAN_COUNT;

@ActivityInfo(layout = R.layout.activity_specialty_dsp,title = "待审批")
public class SpecialtyDspActivity extends BaseActivity {
    @InjectParam
    int id;
    @InjectParam
    SingleBodyartspecialtyEntity data;
    @BindView(R.id.tv_user_name)
    TextView tv_user_name;
    @BindView(R.id.tv_organisers)
    TextView tv_organisers;
    @BindView(R.id.tv_winning_name)
    TextView tv_winning_name;
    @BindView(R.id.tv_win_level)
    TextView tv_win_level;
    @BindView(R.id.tv_winning_level)
    TextView tv_winning_level;
    @BindView(R.id.tv_winning_time1)
    TextView tv_winning_time1;
    @BindView(R.id.tv_winning_type1)
    TextView tv_winning_type1;
    @BindView(R.id.recyc_pic)
    RecyclerView recyc_pic;
    @BindView(R.id.tv_spr)
    TextView tv_spr;
    ChosePicAdapter adapter;
    @BindView(R.id.tv_cb)
    TextView tvCb;
    @Override
    protected void init() {
        SpecialtyDspActivity__JumpCenter.bind(this);
        tv_user_name.setText(data.getStudentName());
        tv_organisers.setText(data.getHostUnit());
        tv_winning_name.setText(data.getName());
        tv_win_level.setText(data.getAwardLevel().getAName());
        tv_winning_level.setText(data.getLevel().getLName());
        tv_winning_time1.setText(data.getPrizeTime());
        if (data.getBigType()==1) {
            tv_winning_type1.setText("艺术类");
        }else {
            tv_winning_type1.setText("体育类");
        }
        if (data.getImage()!= null && !data.getImage().isEmpty()){
            recyc_pic.setLayoutManager(new GridLayoutManager(this, CHOSE_PIC_SPAN_COUNT));
            adapter = new ChosePicAdapter(data.getImage(), this,false);
            recyc_pic.setAdapter(adapter);
        }
        tv_spr.setText(ChosePeopleActivity.getPeoplesInfos1(data.getAuditor()));
        tvCb.setEnabled(!data.isUrge());
    }

    /**
     * 删除。
     */
    @OnClick(R.id.tv_cx)
    void delete() {
        HttpHeper.get().parentService()
                .withDrawBodySpecialty(id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(SpecialtyDspActivity.this,data);
                        finish();
                    }
                });
    }

    /**
     * 催办
     */
    @OnClick(R.id.tv_cb)
    void cb() {
        HttpHeper.get().toolService()
                .cb(ChosePeopleActivity.getIdList2(data.getAuditor()).toString(),id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(SpecialtyDspActivity.this,data);
                        tvCb.setEnabled(false);
                    }
                });
    }
}
